<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>设备管理系统的</title>
    <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
    <link href="css/common.css" rel="stylesheet">
    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/login.css" rel="stylesheet">

    <!-- <link rel="shortcut icon" href="favicon.ico"/> -->
</head>

<body class="login">
<div class="menu-toggler sidebar-toggler">
</div>
<div class="logo">
    <h3 class="logo-title">科大讯飞教育设备报修平台</h3>
</div>
<div class="content" id="template">
    <div class="login-form">
        <h3 class="form-title">用户登录</h3>
        <div id="errorMsg">

        </div>
        <!--
        <div class="alert alert-danger ">
            <button class="close" data-close="alert"></button>
            <span>errorMsg</span>
        </div>
        -->

        <div class="form-group">
            <label class="control-label">用户名</label>
            <input id="username" class="form-control form-control-solid placeholder-no-fix" type="text"
                   autocomplete="off"
                   placeholder="用户名" name="username" value=""/>
        </div>
        <div class="form-group">
            <label class="control-label">密码</label>
            <input id="password" class="form-control form-control-solid placeholder-no-fix" type="password"
                   autocomplete="off"
                   placeholder="密码" name="password" value=""/>
        </div>
        <div class="form-actions">
            <button type="submit" class="btn btn-success" id="btn-submit">确定登录</button>
            <!--<label class="rememberme check">
                <input type="checkbox" name="remember" value="1" checked="checked"/>记住我 </label>
            <a href="javascript:;" id="forget-password" class="forget-password">忘记密码？</a>-->
        </div>
    </div>

    <!--<form class="forget-form" onsubmit="return inspect();">
        <h3>忘记密码?</h3>
        <p>
            输入你的邮箱找回你的密码
        </p>
        <div class="form-group">
            <input class="form-control" type="text" autocomplete="off" placeholder="Email" name="email" id="email"/>
        </div>
        <div class="form-actions">
            <button type="button" id="back-btn" class="btn btn-default">返回</button>
            <button type="submit" class="btn btn-success pull-right">确定提交</button>
        </div>
    </form>-->
</div>
<div class="copyright">
    2019 © 科大讯飞教研项目组.
</div>
</body>
</html>
<script src="js/jquery-2.0.2.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js" type="text/javascript"></script>
<script src="js/jquery.cookie-1.4.1.js"></script>
<script type="text/javascript">
    $('#forget-password').click(function () {
        $('.login-form').hide();
        $('.forget-form').show();
    });

    $('#back-btn').click(function () {
        $('.login-form').show();
        $('.forget-form').hide();
    });
</script>
<script type="text/javascript">
    $(function () {
        if ($('input[name="username"]').val() == null || $('input[name="password"]').val() == null) {
            $('input[name="username"]').attr({"value": "用户名"});
            $('input[name="password"]').attr({"value": "密码"});
        }
    });

</script>
<script type="text/javascript">
    function inspect() {
        var emailNode = document.getElementById("email");
        regEmail = /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/;
        if (emailNode.value.length == 0) {
            alert("邮箱号不能为空");
            return false;
        }
        if (!regEmail.test(emailNode.value)) {
            alert("输入格式有误！");
            return false;
        }
        return true;
    }

</script>
<script>
    $("#btn-submit").click(function () {
        let username = $("#username").val();
        let password = $("#password").val();
        if (username == null || username.length < 1) {
            alert("请输入账号！")
            return;
        }
        if (password == null || password.length < 1) {
            alert("请输入密码！")
            return;
        }
        $.ajax({
            type: "post",
            // dataType: "json",
            contentType: "application/json;charset=utf-8",
            url: "http://localhost/home/login",
            data: JSON.stringify({
                "userName": username,
                "password": password
            }),
            success: function (result) {
                console.log(result);
                if (result.code != 0) {
                    let html = "";
                    html += "<div class=\"alert alert-danger\">";
                    html += "<button class=\"close\" data-close=\"alert\"></button>";
                    html += "<span>" + result.msg + "</span>";
                    html += "</div>";
                    $("#errorMsg").html(html);
                } else {
                    // console.log(result.data);
                    $.cookie("username", result.data.userName);
                    $.cookie("uid", result.data.id);
                    alert("登录成功！");
                    window.location.href = "index.html";
                }

            },
            error: function (e) {
                alert("error")
                console.log(e);
            }
        });
    })

</script>

<script>
    $(function () {
        /**
         * {code:0,data:{ }}
         */
        $.ajax({
            type: "get",
            url: "http://localhost/equipment/getOne/1",
            success: function (result) {
                console.log(result);
            }
        });
    });
</script>